I'm setting up a 3W laser diode on my CNC router (which has kflop & kstep), and I want to share my idea for switching the laser on/off so that people more familiar with kflop can give me any better suggestions.
The laser driver draws ~1.7A@12V so I will use relay output 0 to drive a normal mechanical relay which powers the laser. When I have time I'll try to find a suitable NPN to get faster switching than a relay.
My G-code is created to suit engraving, so it has "G0 Z#1" to raise the tool (safe Z moves) and "G1 Z#2" to lower the tool (start cutting). So I was planning to use find/replace in my G-code to swap all "G0 Z#1" lines to M110, and all "G1 Z#2" to M111.
M110 would then call a laser-switch-on thread including SetBit(0); and M111 would call a laser-switch-off thread including ClearBit(0); If I find that the laser takes a while to switch on, I could pause motion with a "G4 0.25" after each of my M code calls to allow time to start/stop the laser
Does that sound like a fairly logical method?
The second approach that I was considering, was not to use the M-codes at all, and basically execute a c program that turns on the laser on if the z value matches the engraving value. eg:
if(ch2->Position==-0.2) // If gcode says to lower engraving tool
{
SetBit(0); //turn laser on
}
else
{
ClearBit(0); //turn laser off
}
This seems easier, and doesn't need changes to the gcode, but I don't know how I could pause motion for a short time after turning the laser on/off. I expect that the multitasking nature of kflop means that the motion controller would keep the laser moving, even if I put some sort of wait function after the setbit and clearbit int the c code... is that true?
Cheers,
Tim